﻿Public Class DIAGCODE
    Private ICDID As Integer = Nothing
    Private ICDCODE As String = Nothing
    Private ICDDESC_EN As String = Nothing
    Private ICDDESC_TH As String = Nothing
    Private ICDEXP As String = Nothing
    Private ICDTYPE As Integer = Nothing
    Private STATUS = Nothing
    Private F_CHRONIC = Nothing
    Private F_INFEC = Nothing
    Private F_IMP = Nothing
    Private ICDGRP As String = Nothing
    Private SelectDiag = Nothing
    Dim connect As CONDB = CONDB.NewConnection()
    Property SelectDiag_() As String
        Get
            SelectDiag = "SELECT `icdid`,`icdcode` as 'รหัส ICD',`icddesc_en` as 'ชื่อสากล',`icddesc_th` as 'ชื่อไทย',`icdexp` as 'วันที่ยกเลิก',`icdtype` as 'ประเภท ICD',`status` as 'สถานะการเปิดใช้งาน',CASE WHEN(`f_chronic` IS NULL) THEN 0 ELSE 1 END AS f_chronic,CASE WHEN (`f_infec` IS NULL) THEN 0 ELSE 1 END AS f_infec,CASE WHEN (`f_imp` IS NULL) THEN 0 ELSE 1 END AS f_imp ,`icdgrp` as 'รหัสกลุ่ม ICD'"
            SelectDiag += "FROM masdiagcode;"
            Return SelectDiag
        End Get
        Set(value As String)

        End Set
    End Property
    Property ICDGRP_() As String
        Get
            Return ICDGRP
        End Get
        Set(value As String)
            ICDGRP = value
        End Set
    End Property
    Property F_IMP_() As Boolean
        Get
            Return F_IMP
        End Get
        Set(value As Boolean)
            If value = True Then
                F_IMP = 1
            Else
                F_IMP = 0
            End If
        End Set
    End Property
    Property F_INFEC_() As Boolean
        Get
            Return F_INFEC
        End Get
        Set(value As Boolean)
            If value = True Then
                F_INFEC = 1
            Else
                F_INFEC = 0
            End If
        End Set
    End Property
    Property F_CHRONIC_() As Boolean
        Get
            Return F_CHRONIC
        End Get
        Set(value As Boolean)
            If value = True Then
                F_CHRONIC = 1
            Else
                F_CHRONIC = 0
            End If
        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property ICDTYPE_() As Integer
        Get
            Return ICDTYPE
        End Get
        Set(value As Integer)
            ICDTYPE = value
        End Set
    End Property
    Property ICDEXP_() As String
        Get
            Return ICDEXP
        End Get
        Set(value As String)
            ICDEXP = value
        End Set
    End Property
    Property ICDDESC_TH_() As String
        Get
            Return ICDDESC_TH
        End Get
        Set(value As String)
            ICDDESC_TH = value
        End Set
    End Property
    Property ICDDESC_EN_() As String
        Get
            Return ICDDESC_EN
        End Get
        Set(value As String)
            ICDDESC_EN = value
        End Set
    End Property
    Property ICDCODE_() As String
        Get
            Return ICDCODE
        End Get
        Set(value As String)
            ICDCODE = value
        End Set
    End Property
    Property ICDID_() As Integer
        Get
            Return ICDID
        End Get
        Set(value As Integer)
            ICDID = value
        End Set
    End Property
    Public Sub insertDiagcodeData()
        'If connect.GetTable("SELECT `TMPID` FROM RGTONBILL WHERE `TMPID` = '" & TMPID & "'").Rows.Count > 0 Then
        '    MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
        'Else
        Try
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            'connectlocal = conlocal.NewConnection()
            Dim Sql As String
            Sql = "INSERT INTO masdiagcode "
            Sql += "(`icdcode`,`icddesc_en`,`icddesc_th`,`icdexp`,`icdtype`,`status`,`f_chronic`,`f_infec`,`f_imp`,`icdgrp`) "
            Sql += " VALUES ("
            Sql += "'" & ICDCODE & "',"
            Sql += "'" & ICDDESC_EN & "',"
            Sql += "'" & ICDDESC_TH & "',"
            If ICDEXP Is Nothing Then
                Sql += "Null,"
            Else
                Sql += "'" & ICDEXP & "',"
            End If
            Sql += "'" & ICDTYPE & "',"
            Sql += "'" & STATUS & "',"
            Sql += "'" & F_CHRONIC & "',"
            Sql += "'" & F_INFEC & "',"
            Sql += "'" & F_IMP & "',"
            Sql += "'" & ICDGRP & "')"
            connect.ExecuteNonQuery(Sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
        'End If
    End Sub
    Public Sub editDiagcodedata()
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Try
            'connectlocal = conlocal.NewConnection()
            Dim sql As String
            sql = "UPDATE masdiagcode SET `status` = '" & STATUS & "',"
            sql += "`icdcode` = '" & ICDCODE & "',"
            sql += "`icddesc_en` = '" & ICDDESC_EN & "',"
            sql += "`icddesc_th` = '" & ICDDESC_TH & "',"
            If ICDEXP Is Nothing Then
                sql += "`icdexp` = Null,"
            Else
                sql += "`icdexp` = '" & ICDEXP & "',"
            End If
            sql += "`icdtype` = '" & ICDTYPE & "',"
            If F_CHRONIC Is Nothing Then
                sql += "`f_chronic` = Null,"
            Else
                sql += "`f_chronic` = '" & F_CHRONIC & "',"
            End If
            If F_IMP Is Nothing Then
                sql += "`f_imp` = Null,"
            Else
                sql += "`f_imp` = '" & F_IMP & "',"
            End If
            If F_INFEC Is Nothing Then
                sql += "`f_infec` = Null,"
            Else
                sql += "`f_infec` = '" & F_INFEC & "',"
            End If
            sql += "`icdgrp` = '" & ICDGRP & "' "
            sql += "WHERE `icdid` = '" & ICDID & "'"
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
    End Sub
End Class
